home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 31 < prev    next >
Text File  |  1996-08-06  |  2KB  |  48 lines

  1. Path: gabi-soft.fr!not-for-mail
  2. From: kanze@gabi-soft.fr (J. Kanze)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Faster FILE subroutines in standard C?
  5. Date: 5 Jan 1996 13:05:55 +0100
  6. Organization: GABI Software, Sarl.
  7. Message-ID: <4cj473$n0m@gabi.gabi-soft.fr>
  8. References: <4cfm7c$dot@sunburst.ccs.yorku.ca>
  9. NNTP-Posting-Host: gabi.gabi-soft.fr
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Kenneth Kafieh (ken@yorku.ca) wrote:
  13.  
  14. |> I found that I was able to get 3-4 time faster performance by using good 
  15. |> old ANSI C file accessing routines (like  fgets, fseek, ftell, ...etc.)
  16. |> instead of C++ streams (like ifstream::getline, fstream::seekg, ...etc.)
  17. |> I wrote the program originally in C++ (a simple little phonebook for my
  18. |> own use) and it took about 9 seconds to scan a 100Kb file for a 3 byte
  19. |> string!!!  Fed up, I rewrote it in C and voila! Now it takes 2 secs!
  20. |> I'm using Borland C++ v2.0.
  21.  
  22. |> Does that sound right?  Maybe my code was inefficiently written?
  23. |> I know C++ is generally slower than C but I didn't think that 
  24. |> file stuff would be too.   What did I do wrong? Am I missing
  25. |> something.  Maybe I'll post the code too, later. Has anyone
  26. |> else noticed this too?
  27.  
  28. This depends on the implementation.  With g++ 2.7.2 (libg++ 2.7.1), for
  29. example, formatted output with iostream is more than twice as fast as
  30. using fprintf.
  31.  
  32. |> Come to think of it, the coding in
  33. |> C was cleaner looking, too.  
  34.  
  35. And more error prone (putting on my abestos suit).
  36.  
  37. More to the point: I'm currently reading this in comp.std.c, so I would
  38. guess that iostream is irrelevant, off-topic, and doesn't necessarily
  39. interest all of the readers.  In C, you don't have the choice.  (The
  40. same article was posted to comp.lang.c++.moderated, where it is
  41. relevant.  I would suggest that anyone wishing to follow up to this
  42. posting do so there.)
  43. -- 
  44. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  45. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  46. Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
  47.               -- A la recherche d'une activitΘ dans une region francophone
  48.